package com.lanswon.qzsmk.controller.inventoryManageController;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.qzsmk.service.systemManageService.InventoryManagementService;

import ch.qos.logback.classic.Logger;

@Controller
@RequestMapping(value = "/inventoryMagOfSurplus")
public class InventoryMagOfSurplusController {
	
	private final static Logger logger = (Logger) LoggerFactory.getLogger(InventoryMagOfSurplusController.class);
	
	@Autowired
	InventoryManagementService ims;
	
	@RequiresPermissions("inventoryMagOfSurplus:index")
	@RequestMapping(name = "盘盈入库页面,inventoryMagOfSurplus:index",value = "/surplusInventory", method = { RequestMethod.POST, RequestMethod.GET })
	public String surplusInventory(HttpServletRequest request){
		return "SurplusInventory";
	}
	
	@RequiresPermissions("inventoryMagOfSurplus:toSaveSurplusRecords")
	@RequestMapping(name = "盘盈入库登记,inventoryMagOfSurplus:toSaveSurplusRecords",value="/toSaveSurplusRecords",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> toSaveSurplusRecords(HttpServletRequest request) throws Exception{
		Map<String, Object> resultMap = null;
		resultMap = ims.saveSurplusCardRecords(request);
		logger.debug("resultMap===>" + resultMap);
		// 生成PDF
		ims.createStoragePDF(resultMap);
		Map<String, Object> map = new HashMap<String,Object>();
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("applyType", resultMap.get("credential_type"));
		
		map.put("storageNo", resultMap.get("storageNo"));
		map.put("max", "true");
		map.put("title", resultMap.get("title"));
		map.put("rel", "receiveTask");
		map.put("statusCode", "200");
		map.put("message", "盘盈入库成功");
		map.put("param", paramMap);
		map.put("url", "printCredentials/toStoragePdfView");
		
		map.put("jumpToTile", "盘盈入库");
		map.put("jumpToTabid", "surplusInventory");
		map.put("jumpToUrl", "inventoryMagOfSurplus/surplusInventory");
		return map;
	}	
}
